package com.forum.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.forum.common.Result;
import com.forum.dto.ArticleAuditRequest;
import com.forum.dto.AuditRecordDto;
import com.forum.service.ArticleAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/articles")
public class ArticleAuditController {

    @Autowired
    private ArticleAuditService articleAuditService;


    /**
     * GET /api/articles/audit-records?pageNum=1&pageSize=10
     * 分页查询审核记录列表
     */
    @GetMapping("/audit-records")
    public Result<IPage<AuditRecordDto>> listAuditRecords(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize,@RequestParam(defaultValue = "") String searchKey) {
        return articleAuditService.getAuditRecordList(page, pageSize,searchKey);
    }

    /**
     * 文章审核接口
     * 请求体示例：
     * {
     *    "articleId": 123,
     *    "approved": true,
     *    "comment": "审核通过，文章内容符合要求"
     * }
     */
    @PostMapping("/audit")
    public Result<String> auditArticle(@RequestBody ArticleAuditRequest request) {
        return articleAuditService.auditArticle(request);
    }
}
